import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import '@/assets/stylus/index.styl'
import Swiper from 'swiper'
import 'swiper/dist/css/swiper.css'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
// 模似数据
import mockData from 'mockjs'
Vue.prototype.$mock = mockData
// 生产环境跨域
if (process.env.NODE_ENV == 'development') {
  console.log('开发环境')
} else {
  Axios.defaults.baseURL = config.URL
}
// 点击自动复制
import clipboard from 'clipboard';
Vue.prototype.clipboard = clipboard;
import Request from './common/mixins/Exception.js' // axios请求封装（异常处理）
import loading from './common/mixins/loading.js'// 全局加载中
import apiResponse from '@/common/mixins/apiResponse.js' // 高阶请求封装
Vue.mixin(Request).mixin(loading).mixin(apiResponse)
import {
  Dropdown, DropdownMenu,DropdownItem, Input,Row, Col, Table, TableColumn,Message, Upload,
   Button as elButton, Steps,Step, DatePicker ,Loading, Progress
} from 'element-ui'
import {
  Tabbar, TabbarItem,Button,NavBar,Tab,Tabs,Search,Actionsheet,DatetimePicker, Picker,Popup, Toast,Icon,Cell,CellGroup,Field,
  Uploader,Tag,Checkbox,Collapse,CollapseItem,CheckboxGroup,Row as vantRow,Col as vantCol,Steps as vantSteps,Step as vantStep,
  Radio, RadioGroup,NumberKeyboard, Circle,Area ,List,Dialog,PullRefresh 
} from 'vant'


Vue.use(Tabbar).use(TabbarItem).use(NavBar).use(Tab).use(Tabs).use(Search).use(Table).use(TableColumn).use(Dropdown).use(CellGroup).use(Field).use(Uploader)
.use(DropdownItem).use(DropdownMenu).use(Actionsheet).use(DatetimePicker).use(Popup).use(Toast).use(Icon).use(Cell).use(Tag).use(Steps).use(Step).use(Checkbox)
.use(Input).use(vantRow).use(vantCol).use(Button).use(Row).use(Col).use(elButton).use(Collapse).use(CollapseItem).use(Upload).use(Radio).use(RadioGroup).use(NumberKeyboard)
.use(Picker).use(CheckboxGroup).use(Circle).use(vantSteps).use(vantStep).use(Area).use(DatePicker).use(Loading).use(List).use(Dialog).use(PullRefresh).use(Progress)
Vue.use(ElementUI);
// 时间过滤器
Vue.filter('formatterTime', function(row, column) {
  if (!row) return "";
  return row.substring(0, row.indexOf("T"));
});
Vue.prototype.$message = Message
Vue.prototype.$toast = Toast
// Vue.prototype.$notifi = Notification
import 'element-ui/lib/theme-chalk/index.css'
import "lib-flexible/flexible.js"
// fade/zoom 等
import 'element-ui/lib/theme-chalk/base.css'
// collapse 展开折叠
import CollapseTransition from 'element-ui/lib/transitions/collapse-transition'
import echarts from 'echarts/dist/echarts.min.js'

Vue.component(CollapseTransition.name, CollapseTransition)


/** 加入Axios请求 qs处理GET参数 配置axios全局默认值*/
import qs from 'qs'
import Axios from 'axios'

Axios.defaults.timeout = config.timeout
Axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'

Vue.prototype.$echarts = echarts
Vue.prototype.$dialog = Dialog
Vue.prototype.$http = Axios
Vue.prototype.$qs = qs
Vue.config.productionTip = false
Vue.prototype.$Swiper = Swiper

/**
 * 监测物理返回
 * @type {number}
 */
let jilu=0;
document.addEventListener('plusready', function() {
  // eslint-disable-next-line
  var webview = plus.webview.currentWebview();
  // eslint-disable-next-line
  plus.key.addEventListener('backbutton', function() {
    webview.canBack(function(e) {
      if(e.canBack) {
        if(jilu==0){
          // eslint-disable-next-line
          // plus.nativeUI.toast("双击退出应用");
          jilu++;
          setTimeout(function() {
            jilu = 0;
          }, 1000);
          webview.back();//返回
          return false;
        }
        webview.close();
      } else {
        if(jilu==0){
          // plus.nativeUI.toast("双击退出应用");
          jilu++;
          setTimeout(function() {
            jilu = 0;
          }, 1000);
          webview.back();//返回
          return false;
        }
        webview.close();
      }
    })
  });
});

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
//全局混入